<template>
  <view class="page">
    <image src="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/top-bg.png" class="bg-color"
      mode="aspectFill"></image>
    <z-paging-swiper>
      <template #top>
        <uv-navbar bgColor="rgba(0,0,0,0)" @leftClick="leftClick" :fixed="false" title="售后详情"></uv-navbar>

        <view class="tab-box">
          <view class="tab-box-content">
            <uv-tabs :list="data.tabList" :itemStyle="{ height: '100rpx' }"
              :inactiveStyle="{ color: '#828A9D', fontSize: '28rpx' }"
              :activeStyle="{ color: '#3B75FF', fontSize: '28rpx' }" lineColor="#3B75FF" @change="tabActiveFunc"
              :current="data.tabActive"></uv-tabs>
          </view>
        </view>
      </template>

      <swiper class="swiper" :current="data.tabActive" @animationfinish="swiperAnimationfinish">
        <swiper-item class="swiper-item">
          <z-paging ref="paging2" refresher-only @onRefresh="onRefresh('paging2')">
            <!-- 操作历史 -->
            <view class="project-box">
              <view class="uv-steps-box">
                <uv-steps direction="column">
                  <uv-steps-item v-for="(item, index) in asInfo.log_list" :key="index">
                    <template v-slot:icon>
                      <view class="uv-steps-box-tips"></view>
                    </template>
                    <template v-slot:desc>
                      <view class="steps-box">
                        <view class="steps-box-top">
                          <view class="time">{{ item.created_at }}</view>
                          <view class="user-data">
                            <image class="user-avater" :src="item.handlers_image"></image>
                            <view class="user-name">{{ item.handlers_name }}-{{ item.handlers_position }}</view>
                          </view>
                        </view>
                        <view class="steps-box-data">
                          <view class="steps-box-data-title">{{ item.content }}</view>

                          <view class="table-content" v-if="item.after_sales_status == 20">
                            <view class="table-item">
                              <view class="table-item-title">工程监理</view>
                              <view class="table-item-content">{{ asInfo.engineering_supervision_name }}</view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">内容描述</view>
                              <view class="table-item-content">{{ asInfo.problem_content }}</view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">附件</view>
                              <view class="table-item-content">
                                <view class="table-item-file-name" v-for="(item2, idx) in asInfo.after_sales_file"
                                  :key="idx" @click="preFileFunc(item2)">
                                  {{ item2.file_name }}
                                </view>
                              </view>
                            </view>
                          </view>

                          <view class="table-content"
                            v-if="item.after_sales_status == 30 && asInfo.user_position == '工程监理'">
                            <view class="table-item">
                              <view class="table-item-title">工程经理</view>
                              <view class="table-item-content">{{ asInfo.engineering_manager_name }}</view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">内容描述</view>
                              <view class="table-item-content">{{ asInfo.problem_content }}</view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">附件</view>
                              <view class="table-item-content">
                                <view class="table-item-file-name" v-for="(item2, idx) in asInfo.after_sales_file"
                                  :key="idx" @click="preFileFunc(item2)">
                                  {{ item2.file_name }}
                                </view>
                              </view>
                            </view>
                          </view>

                          <view class="table-content" v-if="item.after_sales_status == 40">
                            <view class="table-item">
                              <view class="table-item-title">现场核实照片</view>
                              <view class="table-item-content">
                                <view class="table-item-file-name" v-for="(item2, idx) in item.form_data.site_file"
                                  :key="idx" @click="preFileFunc(item2)">
                                  {{ item2.file_name }}
                                </view>
                              </view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">是否需集采订货</view>
                              <view class="table-item-content">{{ item.form_data.is_order_goods == 1 ? '是' : '否' }}
                              </view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">订货需求(明细)</view>
                              <view class="table-item-content">{{ item.form_data.order_demand ?
          item.form_data.order_demand : ' --' }}</view>
                            </view>
                          </view>

                          <view class="table-content" v-if="item.after_sales_status == 50">
                            <view class="table-item w-50" v-if="asInfo.is_order_goods == 1">
                              <view class="table-item-title">订货日期</view>
                              <view class="table-item-content">{{ item.form_data.order_date }}</view>
                            </view>
                            <view class="table-item w-50 m-10" v-if="asInfo.is_order_goods == 1">
                              <view class="table-item-title">到货日期</view>
                              <view class="table-item-content">{{ item.form_data.delivery_date }}</view>
                            </view>
                            <view class="table-item" v-if="asInfo.is_order_goods == 1">
                              <view class="table-item-title">采购专员</view>
                              <view class="table-item-content">{{ item.form_data.procurement_specialist }}</view>
                            </view>
                            <view class="table-item" v-if="asInfo.is_order_goods == 1">
                              <view class="table-item-title">物流单号</view>
                              <view class="table-item-content">{{ item.form_data.odd_numbers }}</view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">限期整改时间</view>
                              <view class="table-item-content">{{ item.form_data.deadline_date }}</view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">责任判定</view>
                              <view class="table-item-content" v-if="item.form_data.responsible_party == 1">施工方责任</view>
                              <view class="table-item-content" v-if="item.form_data.responsible_party == 2">供应商责任</view>
                              <view class="table-item-content" v-if="item.form_data.responsible_party == 3">非施工方&供应商责任
                              </view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">类型划分</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 1">完工未验收</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 2">后区仓库</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 3">甲供物料</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 4">小电器</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 5">灯具</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 6">胶体脱落</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 7">空洞封堵</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 8">给排水</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 9">漏电（线路）</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 10">吊顶补漆</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 11">踢脚线脱落</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 12">肯德基门</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 13">墙板脱落</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 14">瓷砖空鼓（破碎）</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 15">铝塑板脱落</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 16">主体结构</view>
                              <view class="table-item-content" v-if="item.form_data.problem_type == 17">门头漏水</view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">备注</view>
                              <view class="table-item-content">{{ item.form_data.remark ? item.form_data.remark : '--'
                                }}</view>
                            </view>
                          </view>

                          <view class="table-content" v-if="item.after_sales_status == 60">
                            <view class="table-item">
                              <view class="table-item-title w-50">现场完成照片</view>
                              <view class="table-item-content">
                                <view class="table-item-file-name"
                                  v-for="(item2, idx) in item.form_data.completion_file" :key="idx"
                                  @click="preFileFunc(item2)">
                                  {{ item2.file_name }}
                                </view>
                              </view>
                            </view>
                            <view class="table-item">
                              <view class="table-item-title">售后时效</view>
                              <view class="table-item-content">{{ afterSalesTimeliness }}天</view>
                            </view>
                          </view>
                        </view>
                      </view>
                    </template>
                  </uv-steps-item>
                </uv-steps>
              </view>
            </view>
          </z-paging>
        </swiper-item>

        <swiper-item class="swiper-item">
          <z-paging ref="paging1" refresher-only @onRefresh="onRefresh('paging1')">
            <view class="ios">
              <view class="content-box">
                <view class="content-box-item">
                  <view class="title">项目名称</view>
                  <view class="desc">{{ asInfo.xm_project_name }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">项目编号</view>
                  <view class="desc">{{ asInfo.xm_project_number }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">项目客户经理</view>
                  <view class="desc">{{ asInfo.xm_account_manager_name }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">项目工程经理</view>
                  <view class="desc">{{ asInfo.xm_engineering_manager_name }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">项目工程监理</view>
                  <view class="desc">{{ asInfo.xm_engineering_supervision_name }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">结算完成日期</view>
                  <view class="desc">{{ asInfo.xm_settlement_completion_date }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">质保截止日期</view>
                  <view class="desc">{{ asInfo.xm_warranty_deadline_date }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">是否质保期</view>
                  <view class="desc">{{ asInfo.is_sell_by == 1 ? '是' : '否' }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">发起人</view>
                  <view class="desc">{{ asInfo.user_name }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">售后工程经理</view>
                  <view class="desc">{{ asInfo.engineering_manager_name ?? '--' }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">售后工程监理</view>
                  <view class="desc">{{ asInfo.engineering_supervision_name }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">内容描述</view>
                  <view class="desc">{{ asInfo.problem_content }}</view>
                </view>
                <view class="content-box-item">
                  <view class="title">附件</view>
                  <view class="desc">
                    <view @click="preFileFunc(item)" class="file-item underline"
                      v-for="(item, idx) in asInfo.after_sales_file" :key="idx">
                      {{ item.file_name }}
                    </view>
                  </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>

      <!-- 操作区 -->
      <template #bottom>
        <view class="bottom-box ios" v-if="data.userInfo.position_id == 8 && asInfo.after_sales_status == 20">
          <uv-button type="primary" text="分配工程经理" customStyle="width: 100%;" @click="$refs.jlPicker.open()"></uv-button>
        </view>
        <view class="bottom-box ios" v-if="data.userInfo.position_id == 7 && asInfo.after_sales_status == 30">
          <uv-button type="primary" text="现场反馈情况" customStyle="width: 100%;"
            @click="$refs.xcfkqk.open('bottom')"></uv-button>
        </view>
        <view class="bottom-box ios" v-if="data.userInfo.position_id == 8 && asInfo.after_sales_status == 40">
          <uv-button type="primary" text="详情判定提交" customStyle="width: 100%;"
            @click="$refs.xqpdtj.open('bottom')"></uv-button>
        </view>
        <view class="bottom-box ios" v-if="data.userInfo.position_id == 7 && asInfo.after_sales_status == 50">
          <uv-button type="primary" text="整改完成提交" customStyle="width: 100%;"
            @click="$refs.zgwctj.open('bottom')"></uv-button>
        </view>
      </template>
    </z-paging-swiper>

    <!-- 分配工程经理 -->
    <uv-picker title="分配工程经理" ref="jlPicker" :columns="data.jlColumns" @confirm="fpgcjlSubmit"
      keyName="name"></uv-picker>
    <!-- 现场反馈情况 -->
    <uv-popup ref="xcfkqk" mode="bottom" :round="10" @maskClick="closeFunc('xcfkqk')">
      <view class="popup-box">
        <view class="title">现场反馈情况</view>
        <scroll-view class="scroll-view" scroll-y>
          <view class="uv-form-box">
            <uv-form labelPosition="top" :model="data.xcfkqkForm" :rules="data.xcfkqkRules" ref="xcfkqkForm"
              labelWidth="auto">
              <uv-form-item label="是否需集采订货" prop="is_order_goods" labelPosition="left" required>
                <view class="file-box">
                  <uv-switch size="36rpx" v-model="data.xcfkqkForm.is_order_goods"></uv-switch>
                </view>
              </uv-form-item>
              <uv-form-item label="订货需求(明细)" prop="order_demand">
                <uv-textarea height="100" v-model="data.xcfkqkForm.order_demand" placeholder="请输入内容"></uv-textarea>
              </uv-form-item>
              <uv-form-item label="现场核实照片" prop="fileList" required>
                <uv-button type="info" text="点击上传" @click="uploadFunc('xcfkqkForm')" icon="plus" iconSize="24rpx"
                  iconColor="#8F8F8F" customTextStyle="font-size: 24rpx;color: #8F8F8F;"
                  customStyle="width: 170rpx;height: 60rpx;border-radius: 8rpx;"></uv-button>

                <view class="file-item2" v-for="(item, idx) in data.xcfkqkForm.fileList" :key="idx">
                  <view class="file-name2" v-if="item.fileType == 'image'">图片{{ idx }}</view>
                  <view class="file-name2" v-if="item.fileType == 'video'">视频{{ idx }}</view>
                  <view class="file-name2" v-if="item.name">{{ item.name }}</view>
                  <uv-icon name="close" color="#A4A4A4" @click="delFile(idx, 'xcfkqkForm')"></uv-icon>
                </view>
              </uv-form-item>
            </uv-form>
          </view>
        </scroll-view>
        <view class="btn-box">
          <uv-button @click="closeFunc('xcfkqk')" text="取 消" customStyle="width: 180rpx;"></uv-button>
          <uv-button @click="xcfkqkSubmit('xcfkqk')" type="primary" text="提 交" customStyle="width: 500rpx;"></uv-button>
        </view>
      </view>
    </uv-popup>

    <!-- 详情判定提交 -->
    <uv-popup ref="xqpdtj" mode="bottom" :round="10" @maskClick="closeFunc('xqpdtj')">
      <view class="popup-box">
        <view class="title">详情判定提交</view>
        <scroll-view class="scroll-view" scroll-y>
          <view class="uv-form-box">
            <uv-form labelPosition="top" :model="data.xqpdtjForm" :rules="data.xqpdtjRules" ref="xqpdtjForm"
              labelWidth="auto">
              <uv-form-item label="采购专员" prop="procurement_specialist" required v-if="asInfo.is_order_goods == 1">
                <uv-input placeholder="请输入采购专员" v-model="data.xqpdtjForm.procurement_specialist"></uv-input>
              </uv-form-item>
              <uv-form-item label="物流单号" prop="odd_numbers" required v-if="asInfo.is_order_goods == 1">
                <uv-input placeholder="请输入采购专员" v-model="data.xqpdtjForm.odd_numbers"></uv-input>
              </uv-form-item>
              <uv-form-item label="订货日期" prop="order_date" required v-if="asInfo.is_order_goods == 1"
                @click="$refs.dhPicker.open()">
                <uv-input readonly placeholder="请选择订货日期" :value="timestampToDateFormat(data.xqpdtjForm.order_date)"
                  suffixIcon="arrow-right"></uv-input>
              </uv-form-item>
              <uv-form-item label="到货日期" prop="delivery_date" required v-if="asInfo.is_order_goods == 1"
                @click="$refs.dh2Picker.open()">
                <uv-input readonly placeholder="请选择到货日期" :value="timestampToDateFormat(data.xqpdtjForm.delivery_date)"
                  suffixIcon="arrow-right"></uv-input>
              </uv-form-item>
              <uv-form-item label="类型划分" prop="lxType.name" required @click="$refs.lxPicker.open()">
                <uv-input readonly placeholder="请选择类型划分" v-model="data.xqpdtjForm.lxType.name"
                  suffixIcon="arrow-right"></uv-input>
              </uv-form-item>
              <uv-form-item label="责任判定" prop="zrType.name" required @click="$refs.zrPicker.open()">
                <uv-input readonly placeholder="请选择类型划分" v-model="data.xqpdtjForm.zrType.name"
                  suffixIcon="arrow-right"></uv-input>
              </uv-form-item>
              <uv-form-item label="限期整改时间" prop="deadline_date" required @click="$refs.xqPicker.open()">
                <uv-input readonly placeholder="请选择限期整改时间" :value="timestampToDateFormat(data.xqpdtjForm.deadline_date)"
                  suffixIcon="arrow-right"></uv-input>
              </uv-form-item>
              <uv-form-item label="备注" prop="remark">
                <uv-textarea height="100" v-model="data.xqpdtjForm.remark" placeholder="请输入备注"></uv-textarea>
              </uv-form-item>
            </uv-form>
          </view>
        </scroll-view>
        <view class="btn-box">
          <uv-button @click="closeFunc('xqpdtj')" text="取 消" customStyle="width: 180rpx;"></uv-button>
          <uv-button @click="xqpdtjSubmit('xqpdtj')" type="primary" text="提 交" customStyle="width: 500rpx;"></uv-button>
        </view>
      </view>
    </uv-popup>
    <!-- 订货日期 -->
    <uv-datetime-picker ref="dhPicker" :maxDate="Date.now()"
      :value="data.xqpdtjForm.order_date ? data.xqpdtjForm.order_date : Date.now()" mode="date"
      @confirm="pickerConfirm($event, 'order_date')"></uv-datetime-picker>
    <!-- 到货日期 -->
    <uv-datetime-picker ref="dh2Picker" :minDate="data.xqpdtjForm.order_date ? data.xqpdtjForm.order_date : Date.now()"
      v-model="data.xqpdtjForm.delivery_date" mode="date"
      @confirm="pickerConfirm($event, 'delivery_date')"></uv-datetime-picker>
    <!-- 类型划分 -->
    <uv-picker title="类型划分" ref="lxPicker" :columns="data.lxColumns" @confirm="pickerConfirm($event, 'lxType')"
      keyName="name"></uv-picker>
    <!-- 责任判定 -->
    <uv-picker title="责任判定" ref="zrPicker" :columns="data.zrColumns" @confirm="pickerConfirm($event, 'zrType')"
      keyName="name"></uv-picker>
    <!-- 限期整改时间 -->
    <uv-datetime-picker ref="xqPicker" :minDate="Date.now()"
      :value="data.xqpdtjForm.deadline_date ? data.xqpdtjForm.deadline_date : Date.now()" mode="date"
      @confirm="pickerConfirm($event, 'deadline_date')"></uv-datetime-picker>

    <!-- 整改完成提交 -->
    <uv-popup ref="zgwctj" mode="bottom" :round="10" @maskClick="closeFunc('zgwctj')">
      <view class="popup-box">
        <view class="title">整改完成提交</view>
        <scroll-view class="scroll-view" scroll-y>
          <view class="uv-form-box">
            <uv-form labelPosition="top" :model="data.zgwctjForm" :rules="data.zgwctjRules" ref="zgwctjForm"
              labelWidth="auto">
              <uv-form-item label="现场完工照片" prop="fileList" labelPosition="left" required>
                <view class="file-box">
                  <uv-button type="info" text="点击上传" @click="uploadFunc('zgwctjForm')" icon="plus" iconSize="24rpx"
                    iconColor="#8F8F8F" customTextStyle="font-size: 24rpx;color: #8F8F8F;"
                    customStyle="width: 170rpx;height: 60rpx;border-radius: 8rpx;"></uv-button>
                </view>
              </uv-form-item>
              <view class="file-list">
                <view class="file-media" v-for="(item, index) in data.zgwctjForm.fileList" :key="index">
                  <view class="del-icon" @click.stop="delFile(index, 'zgwctjForm')">
                    <uv-icon name="trash" size="15" color="#ffffff"></uv-icon>
                  </view>
                  <image mode="aspectFill" :src="item.tempFilePath" class="media-item"></image>
                </view>
              </view>
            </uv-form>
          </view>
        </scroll-view>
        <view class="btn-box">
          <uv-button @click="closeFunc('zgwctj')" text="取 消" customStyle="width: 180rpx;"></uv-button>
          <uv-button @click="zgwctjSubmit('zgwctj')" type="primary" text="提 交" customStyle="width: 500rpx;"></uv-button>
        </view>
      </view>
    </uv-popup>

	<!-- 文件预览 -->
	<preFileCom :fileObj="fileObj" @onFileSuccess="onFileSuccess"></preFileCom>
  </view>
</template>

<script setup>
import { ref, reactive, computed, getCurrentInstance } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
const { proxy: that } = getCurrentInstance();

const asInfo = ref('');
const data = reactive({
  id: '',
  userInfo: '',
  tabActive: 0,
  tabList: [
    {
      name: '操作历史'
    },
    {
      name: '详细信息'
    }
  ],
  // 分配工程经理
  jlColumns: [],
  // 现场反馈情况
  xcfkqkForm: {
    fileList: [],
    is_order_goods: true,
    order_demand: ''
  },
  xcfkqkRules: {
    fileList: {
      validator: (rule, value, callback) => {
        if (value.length > 0) {
          return true;
        } else {
          return false;
        }
      },
      required: true,
      message: '请上传现场核实照片',
      trigger: 'change'
    },
    order_demand: {
      validator: (rule, value, callback) => {
        if (data.xcfkqkForm.is_order_goods) {
          if (value) {
            return true;
          } else {
            return false;
          }
        } else {
          return true;
        }
      },
      required: true,
      message: '请输入订货需求(明细)',
      trigger: 'change'
    }
  },
  // 详情判定提交
  xqpdtjForm: {
    order_date: '',
    delivery_date: '',
    lxType: '',
    deadline_date: '',
    procurement_specialist: '',
    zrType: '',
    odd_numbers: '',
    remark: ''
  },
  xqpdtjRules: {
    order_date: {
      validator: (rule, value, callback) => {
        if (value) {
          return true;
        } else {
          return false;
        }
      },
      required: true,
      message: '请选择订货日期',
      trigger: 'change'
    },
    delivery_date: {
      validator: (rule, value, callback) => {
        if (value) {
          return true;
        } else {
          return false;
        }
      },
      required: true,
      message: '请选择到货日期',
      trigger: 'change'
    },
    deadline_date: {
      validator: (rule, value, callback) => {
        if (value) {
          return true;
        } else {
          return false;
        }
      },
      required: true,
      message: '请选择限期整改时间',
      trigger: 'change'
    },
    procurement_specialist: { required: true, message: '请输入采购专员', trigger: 'change' },
    'zrType.name': { required: true, message: '请选择责任判定', trigger: 'change' },
    'lxType.name': { required: true, message: '请选择类型划分', trigger: 'change' },
    odd_numbers: { required: true, message: '请输入物流单号', trigger: 'change' }
  },
  lxColumns: [
    [
      {
        name: '完工未验收',
        id: 1
      },
      {
        name: '后区仓库',
        id: 2
      },
      {
        name: '甲供物料',
        id: 3
      },
      {
        name: '小电器',
        id: 4
      },
      {
        name: '灯具',
        id: 5
      },
      {
        name: '胶体脱落',
        id: 6
      },
      {
        name: '空洞封堵',
        id: 7
      },
      {
        name: '给排水',
        id: 8
      },
      {
        name: '漏电（线路）',
        id: 9
      },
      {
        name: '吊顶补漆',
        id: 10
      },
      {
        name: '踢脚线脱落',
        id: 11
      },
      {
        name: '肯德基门',
        id: 12
      },
      {
        name: '墙板脱落',
        id: 13
      },
      {
        name: '瓷砖空鼓（破碎）',
        id: 14
      },
      {
        name: '铝塑板脱落',
        id: 15
      },
      {
        name: '主体结构',
        id: 16
      },
      {
        name: '门头漏水',
        id: 17
      }
    ]
  ],
  zrColumns: [
    [
      {
        name: '施工方责任',
        id: 1
      },
      {
        name: '供应商责任',
        id: 2
      },
      {
        name: '非施工方&供应商责任',
        id: 3
      }
    ]
  ],
  // 整改完成提交
  zgwctjForm: {
    fileList: []
  },
  zgwctjRules: {
    fileList: {
      validator: (rule, value, callback) => {
        if (value.length > 0) {
          return true;
        } else {
          return false;
        }
      },
      required: true,
      message: '请上传现场完成照片',
      trigger: 'change'
    }
  },

  preVideoShow: false,
  currVideo: ''
});
const afterSalesTimeliness = computed(() => {
  let asInfo2 = asInfo.value;
  console.log(asInfo2, 'asdasd’');
  let date = new Date(asInfo2.created_at);
  let year = date.getFullYear();
  let month = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的
  let day = String(date.getDate()).padStart(2, '0');
  let created_at = `${year}-${month}-${day}`;
  if (asInfo2.is_order_goods == 1) {
    let days = getDaysDiff(asInfo2.order_date, asInfo2.delivery_date);
    return getDaysDiff(asInfo2.completion_date, created_at) - days;
  } else {
    return getDaysDiff(asInfo2.completion_date, created_at);
  }
});
function getDaysDiff(date1, date2) {
  date1 = new Date(date1);
  date2 = new Date(date2);
  const oneDay = 24 * 60 * 60 * 1000; // 每天的毫秒数
  const date1Ms = date1.getTime(); // 转换第一个日期为时间戳
  const date2Ms = date2.getTime(); // 转换第二个日期为时间戳
  return Math.round((date2Ms - date1Ms) / oneDay);
}
onLoad((e) => {
  data.id = e.id;
  data.userInfo = uni.getStorageSync('userInfo');
  getAfterSalesDetails();
});

const onRefresh = (name) => {
  getAfterSalesDetails(name);
};
const tabActiveFunc = (e) => {
  data.tabActive = e.index;
};
const swiperAnimationfinish = (e) => {
  console.log(e, 'swiperAnimationfinish');
  data.tabActive = e.detail.current;
};
const getAfterSalesDetails = (name) => {
  that.$hApi
    .getAfterSalesDetails({
      after_sales_id: data.id
    })
    .then((res) => {
      console.log(res, 'getAfterSalesDetails');
      if (res.code == 200) {
        asInfo.value = res.data;

        if (res.data.after_sales_status == 20) {
          getAdminList();
        }
      }
      if (name) {
        that.$refs[name].complete();
      }
    });
};
// 清空弹窗
const closeFunc = (name) => {
  that.$refs[`${name}Form`].resetFields();
  that.$refs[`${name}Form`].clearValidate();
  that.$refs[name].close();
};
const uploadFunc = (formName) => {
  let mediaType = ['image', 'video'];
  if (formName == 'zgwctjForm') {
    mediaType = ['image'];
  }
  uni.chooseMedia({
    mediaType,
    sourceType: ['album', 'camera'],
    success(res) {
      console.log(res.tempFiles);
      res.tempFiles.map((item) => {
        data[formName].fileList.push(item);
      });
      that.$refs[formName].validateField('fileList');
    }
  });
};
const delFile = (idx, formName) => {
  data[formName].fileList.splice(idx, 1);
};
// 分配工程经理
const getAdminList = () => {
  that.$Api
    .wxGetAdminList({
      page: 1,
      num: 99,
      identity: 2,
      position_id_arr: [7]
    })
    .then((res) => {
      console.log(res, 'getAdminList');
      if (res.code == 200) {
        data.jlColumns = [res.data.list];
      }
    });
};
const fpgcjlSubmit = (e) => {
  uni.showLoading({
    mask: true,
    title: '信息提交中...'
  });
  that.$hApi
    .selectEngineeringManager({
      after_sales_id: data.id,
      engineering_manager_id: e.value[0].id,
      engineering_manager_name: e.value[0].name
    })
    .then((res) => {
      uni.hideLoading();
      if (res.code == 200) {
        getAfterSalesDetails();
      }
      uni.showToast({
        title: res.code == 200 ? '操作成功' : res.message,
        icon: res.code == 200 ? 'success' : 'error'
      });
    })
    .catch((err) => {
      uni.hideLoading();
    });
};

// 现场反馈情况
const xcfkqkSubmit = (formName) => {
  that.$refs[`${formName}Form`]
    .validate()
    .then((res) => {
      let xcfkqkForm = data.xcfkqkForm;
      console.log(xcfkqkForm);
      uni.showLoading({
        mask: true,
        title: '信息提交中...'
      });
      that.$upload(xcfkqkForm.fileList)
        .then((res) => {
          console.log(1111, res);
          that.$hApi
            .wxFeedbackSiteSituation({
              after_sales_id: data.id,
              is_order_goods: xcfkqkForm.is_order_goods ? 1 : 2,
              order_demand: xcfkqkForm.order_demand,
              site_file: res.arrResult
            })
            .then((res) => {
              console.log(res, 'wxFeedbackSiteSituation');
              uni.hideLoading();
              if (res.code == 200) {
                closeFunc(formName);
                getAfterSalesDetails();
              }
              uni.showToast({
                title: res.code == 200 ? '操作成功' : res.message,
                icon: res.code == 200 ? 'success' : 'error'
              });
            })
            .catch((err) => {
              uni.hideLoading();
            });
        })
        .catch((err) => {
          uni.hideLoading();
        });
    })
    .catch(() => { });
};
// 详情判定提交
function timestampToDateFormat(timestamp) {
  if (!timestamp) return '';
  const dateObj = new Date(timestamp); // 创建Date对象
  const year = String(dateObj.getFullYear()); // 获取年份
  const month = String(dateObj.getMonth() + 1).padStart(2, '0'); // 获取月份，并补零
  const day = String(dateObj.getDate()).padStart(2, '0'); // 获取日期，并补零

  return year + '-' + month + '-' + day; // 返回转换后的日期格式
}
const pickerConfirm = (e, type) => {
  console.log(e, type);
  switch (type) {
    case 'order_date':
      data.xqpdtjForm.order_date = e.value;
      that.$refs.xqpdtjForm.validateField('order_date');
      break;
    case 'delivery_date':
      data.xqpdtjForm.delivery_date = e.value;
      that.$refs.xqpdtjForm.validateField('delivery_date');
      break;
    case 'deadline_date':
      data.xqpdtjForm.deadline_date = e.value;
      that.$refs.xqpdtjForm.validateField('deadline_date');
      break;
    case 'lxType':
      data.xqpdtjForm.lxType = e.value[0];
      that.$refs.xqpdtjForm.validateField('lxType.name');
      break;
    case 'zrType':
      data.xqpdtjForm.zrType = e.value[0];
      that.$refs.xqpdtjForm.validateField('zrType.name');
      break;
  }
};
const xqpdtjSubmit = (formName) => {
  that.$refs[`${formName}Form`]
    .validate()
    .then((res) => {
      let xqpdtjForm = data.xqpdtjForm;
      uni.showLoading({
        mask: true,
        title: '信息提交中...'
      });
      that.$hApi
        .responsibilityDetermination({
          after_sales_id: data.id,
          order_date: timestampToDateFormat(xqpdtjForm.order_date),
          delivery_date: timestampToDateFormat(xqpdtjForm.delivery_date),
          deadline_date: timestampToDateFormat(xqpdtjForm.deadline_date),
          procurement_specialist: xqpdtjForm.procurement_specialist,
          responsible_party: xqpdtjForm.zrType.id,
          problem_type: xqpdtjForm.lxType.id,
          odd_numbers: xqpdtjForm.odd_numbers,
          remark: xqpdtjForm.remark
        })
        .then((res) => {
          console.log(res, '详情判定提交');
          uni.hideLoading();
          if (res.code == 200) {
            closeFunc(formName);
            getAfterSalesDetails();
          }
          uni.showToast({
            title: res.code == 200 ? '操作成功' : res.message,
            icon: res.code == 200 ? 'success' : 'error'
          });
        })
        .catch((err) => {
          uni.hideLoading();
        });
      console.log(xqpdtjForm);
    })
    .catch(() => { });
};
// 整改完成提交
const zgwctjSubmit = (formName) => {
  that.$refs[`${formName}Form`]
    .validate()
    .then((res) => {
      let zgwctjForm = data.zgwctjForm;
      console.log(zgwctjForm);
      uni.showLoading({
        mask: true,
        title: '信息提交中...'
      });
      that.$upload(zgwctjForm.fileList)
        .then((res) => {
          console.log(1111, res);
          that.$hApi
            .wxAfterSalesRectification({
              after_sales_id: data.id,
              completion_file: res.arrResult
            })
            .then((res) => {
              console.log(res, 'wxAfterSalesRectification');
              uni.hideLoading();
              if (res.code == 200) {
                closeFunc(formName);
                getAfterSalesDetails();
              }
              uni.showToast({
                title: res.code == 200 ? '操作成功' : res.message,
                icon: res.code == 200 ? 'success' : 'error'
              });
            })
            .catch((err) => {
              uni.hideLoading();
            });
        })
        .catch((err) => {
          uni.hideLoading();
        });
    })
    .catch(() => { });
};


let fileObj = ref('');
const preFileFunc = (file) => {
	console.log(file);
	fileObj.value = file;
};
const onFileSuccess = () => {
	fileObj.value = '';
};

const leftClick = () => {
  // 获取当前页面栈数组
  const pages = getCurrentPages();
  // 获取栈顶页面的实例
  const prevPage = pages[pages.length - 2]; //上一页
  if (!prevPage) {
    uni.reLaunch({
      url: '/pages/index/index'
    });
  } else {
    uni.navigateBack();
  }
  console.log('返回上一页', prevPage);
};
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
